package com.example.myspringframework.context.support;

import cn.hutool.core.bean.BeanException;
import com.example.myspringframework.beans.BeansException;
import com.example.myspringframework.beans.factory.ConfigurableListableBeanFactory;
import com.example.myspringframework.beans.factory.support.DefaultListableBeanFactory;

public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{
    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeanException {
        DefaultListableBeanFactory beanFactory = this.createBeanFactory();
        this.loadBeanDefinitions(beanFactory);
        this.beanFactory=beanFactory;
    }

    @Override
    public ConfigurableListableBeanFactory getBeanFactory() {
        return this.beanFactory;
    }
    protected DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }
    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException;

}
